﻿using System;
using System.IO;
using SEXY;
using UnityEngine;

namespace Character
{
	// Token: 0x020001AF RID: 431
	public class CustomParameter : ParameterBase
	{
		// Token: 0x06000B23 RID: 2851 RVA: 0x00040C0C File Offset: 0x0003EE0C
		public CustomParameter(SEX sex) : base(sex)
		{
			this.sex = sex;
			this.hair = new HairParameter(sex);
			this.head = new HeadParameter(sex);
			this.body = new BodyParameter(sex);
			this.wear = new WearParameter(sex);
			this.acce = new AccessoryParameter(sex);
		}

		// Token: 0x06000B24 RID: 2852 RVA: 0x00040C64 File Offset: 0x0003EE64
		public CustomParameter(CustomParameter copy) : base(copy.sex)
		{
			this.hair = new HairParameter(copy.hair);
			this.head = new HeadParameter(copy.head);
			this.body = new BodyParameter(copy.body);
			this.wear = new WearParameter(copy.wear);
			this.acce = new AccessoryParameter(copy.acce);
		}

		// Token: 0x06000B25 RID: 2853 RVA: 0x00040CD4 File Offset: 0x0003EED4
		public void Copy(CustomParameter copy, int filter = -1)
		{
			if (copy == null)
			{
				return;
			}
			if (this.sex != copy.sex)
			{
				GlobalData.Debug_LogWarning("我们复制了不同性别的数据");
			}
			this.sex = copy.sex;
			if ((filter & 1) != 0)
			{
				this.hair.Copy(copy.hair);
			}
			if ((filter & 2) != 0)
			{
				this.head.Copy(copy.head);
			}
			if ((filter & 4) != 0)
			{
				this.body.Copy(copy.body);
			}
			if ((filter & 8) != 0)
			{
				this.wear.Copy(copy.wear);
				this.wear.CheckHasData();
			}
			if ((filter & 16) != 0)
			{
				this.acce.Copy(copy.acce);
				this.acce.CheckHasData();
			}
		}

		// Token: 0x06000B26 RID: 2854 RVA: 0x00040DA4 File Offset: 0x0003EFA4
		private void Init()
		{
			this.hair.Init();
			this.head.Init();
			this.body.Init();
			this.wear.Init();
			this.acce.Init();
		}

		// Token: 0x06000B27 RID: 2855 RVA: 0x00040DE0 File Offset: 0x0003EFE0
		private void InitCoordinate()
		{
			this.wear.Init();
			this.acce.Init();
		}

		// Token: 0x06000B28 RID: 2856 RVA: 0x00040DF8 File Offset: 0x0003EFF8
		public void FromSexyData(CharFemaleFile sexy)
		{
			this.Init();
			this.FromSexyData_Common(sexy);
			this.head.eyeLashID = sexy.femaleCustomInfo.matEyelashesId;
			this.head.eyeLashColor.FromSexyData(sexy.femaleCustomInfo.eyelashesColor);
			this.head.eyeshadowTexID = sexy.femaleCustomInfo.texEyeshadowId;
			this.head.eyeshadowColor = sexy.femaleCustomInfo.eyeshadowColor.rgbaDiffuse;
			this.head.cheekTexID = sexy.femaleCustomInfo.texCheekId;
			this.head.cheekColor = sexy.femaleCustomInfo.cheekColor.rgbaDiffuse;
			this.head.lipTexID = sexy.femaleCustomInfo.texLipId;
			this.head.lipColor = sexy.femaleCustomInfo.lipColor.rgbaDiffuse;
			this.head.moleTexID = sexy.femaleCustomInfo.texMoleId;
			this.head.moleColor = sexy.femaleCustomInfo.moleColor.rgbaDiffuse;
			this.head.eyeHighlightTexID = sexy.femaleCustomInfo.matEyeHiId;
			this.head.eyeHighlightColor.FromSexyData(sexy.femaleCustomInfo.eyeHiColor);
			this.head.eyeHighlightColor.specColor1 = Color.white;
			this.body.sunburnID = sexy.femaleCustomInfo.texSunburnId;
			this.body.nipID = sexy.femaleCustomInfo.matNipId;
			this.body.nipColor.FromSexyData(sexy.femaleCustomInfo.nipColor);
			this.body.underhairID = sexy.femaleCustomInfo.matUnderhairId;
			this.body.underhairColor.mainColor = sexy.femaleCustomInfo.underhairColor.rgbaDiffuse;
			this.body.underhairColor.metallic = 0f;
			this.body.underhairColor.smooth = 0.5f;
			this.body.nailColor.Init(false, 1f);
			this.body.manicureColor.FromSexyData(sexy.femaleCustomInfo.nailColor);
			this.body.manicureColor.mainColor1.a = 0f;
			this.body.areolaSize = sexy.femaleCustomInfo.areolaSize;
			this.body.bustSoftness = sexy.femaleCustomInfo.bustSoftness;
			this.body.bustWeight = sexy.femaleCustomInfo.bustWeight;
			CharFileInfoClothesFemale charFileInfoClothesFemale = sexy.femaleCoordinateInfo.GetInfo(CharDefine.CoordinateType.type00) as CharFileInfoClothesFemale;
			for (int i = 0; i < 11; i++)
			{
				this.wear.wears[i].id = charFileInfoClothesFemale.clothesId[i];
				if (this.wear.wears[i].color == null)
				{
					this.wear.wears[i].color = new ColorParameter_PBR2();
				}
				this.wear.wears[i].color.FromSexyData(charFileInfoClothesFemale.clothesColor[i], charFileInfoClothesFemale.clothesColor2[i]);
			}
			this.wear.isSwimwear = charFileInfoClothesFemale.swimType;
			this.wear.swimOptTop = !charFileInfoClothesFemale.hideSwimOptTop;
			this.wear.swimOptBtm = !charFileInfoClothesFemale.hideSwimOptBot;
			int num = this.body.shapeVals.Length - 1;
			this.body.shapeVals[num] = 0f;
		}

		// Token: 0x06000B29 RID: 2857 RVA: 0x00041170 File Offset: 0x0003F370
		public void FromSexyData(CharMaleFile sexy)
		{
			this.Init();
			this.FromSexyData_Common(sexy);
			this.head.beardID = sexy.maleCustomInfo.matBeardId;
			this.head.beardColor = sexy.maleCustomInfo.beardColor.rgbaDiffuse;
			this.body.underhairID = 0;
			this.body.underhairColor = new ColorParameter_Alloy();
			this.body.underhairColor.mainColor = Color.black;
			this.body.underhairColor.metallic = 0f;
			this.body.underhairColor.smooth = 0.5f;
			CharFileInfoClothes info = sexy.maleCoordinateInfo.GetInfo(CharDefine.CoordinateType.type00);
			int num = 0;
			int num2 = 1;
			if (this.wear.wears[0].color == null)
			{
				this.wear.wears[0].color = new ColorParameter_PBR2();
			}
			if (this.wear.wears[10].color == null)
			{
				this.wear.wears[10].color = new ColorParameter_PBR2();
			}
			this.wear.wears[0].id = info.clothesId[num];
			this.wear.wears[0].color.FromSexyData(info.clothesColor[num], info.clothesColor2[num]);
			this.wear.wears[10].id = info.clothesId[num2];
			this.wear.wears[10].color.FromSexyData(info.clothesColor[num2], info.clothesColor2[num2]);
		}

		// Token: 0x06000B2A RID: 2858 RVA: 0x0004130C File Offset: 0x0003F50C
		private void FromSexyData_Common(CharFile sexy)
		{
			this.body.bodyID = sexy.customInfo.texBodyDetailId;
			this.body.detailID = sexy.customInfo.texBodyDetailId;
			this.body.detailWeight = sexy.customInfo.bodyDetailWeight;
			this.body.skinColor.FromSexyData(sexy.customInfo.skinColor);
			this.body.tattooID = sexy.customInfo.texTattoo_bId;
			this.body.tattooColor = sexy.customInfo.tattoo_bColor.rgbaDiffuse;
			sexy.customInfo.shapeValueBody.CopyTo(this.body.shapeVals, 0);
			this.head.headID = sexy.customInfo.headId;
			this.head.faceTexID = sexy.customInfo.texFaceId;
			this.head.tattooID = sexy.customInfo.texTattoo_fId;
			this.head.tattooColor = sexy.customInfo.tattoo_fColor.rgbaDiffuse;
			this.head.eyeBrowID = sexy.customInfo.matEyebrowId;
			this.head.eyeBrowColor.FromSexyData(sexy.customInfo.eyebrowColor);
			this.head.eyeID_L = sexy.customInfo.matEyeLId;
			this.head.eyeIrisColorL = sexy.customInfo.eyeLColor.rgbDiffuse;
			this.head.eyeID_R = sexy.customInfo.matEyeRId;
			this.head.eyeIrisColorR = sexy.customInfo.eyeRColor.rgbDiffuse;
			this.head.eyeScleraColorL = sexy.customInfo.eyeWColor.rgbDiffuse;
			this.head.eyeScleraColorR = sexy.customInfo.eyeWColor.rgbDiffuse;
			this.head.detailID = sexy.customInfo.texFaceDetailId;
			this.head.detailWeight = sexy.customInfo.faceDetailWeight;
			this.head.eyePupilDilationL = 0f;
			this.head.eyePupilDilationR = 0f;
			this.head.eyeEmissiveL = 0.5f;
			this.head.eyeEmissiveR = 0.5f;
			this.head.shapeVals = new float[sexy.customInfo.shapeValueFace.Length];
			sexy.customInfo.shapeValueFace.CopyTo(this.head.shapeVals, 0);
			int num = (this.sex != SEX.FEMALE) ? 1 : 3;
			for (int i = 0; i < num; i++)
			{
				this.hair.parts[i].ID = sexy.customInfo.hairId[i];
				if (this.hair.parts[i].hairColor == null)
				{
					this.hair.parts[i].hairColor = new ColorParameter_Hair();
				}
				this.hair.parts[i].hairColor.FromSexyData(sexy.customInfo.hairColor[i]);
				this.hair.parts[i].acceColor = null;
			}
			CharFileInfoClothes info = sexy.coordinateInfo.GetInfo(CharDefine.CoordinateType.type00);
			for (int j = 0; j < 10; j++)
			{
				CharFileInfoClothes.Accessory accessory = info.accessory[j];
				this.acce.slot[j].Set((ACCESSORY_TYPE)accessory.type, accessory.id, accessory.parentKey);
				this.acce.slot[j].addPos = accessory.addPos;
				this.acce.slot[j].addRot = accessory.addRot;
				this.acce.slot[j].addScl = accessory.addScl;
				if (this.acce.slot[j].color == null)
				{
					this.acce.slot[j].color = new ColorParameter_PBR2();
				}
				this.acce.slot[j].color.FromSexyData(accessory.color, accessory.color2);
			}
		}

		// Token: 0x06000B2B RID: 2859 RVA: 0x00041728 File Offset: 0x0003F928
		public void FromSexyCoordinateData(CharFileInfoClothesFemale sexyCoord)
		{
			this.InitCoordinate();
			this.FromSexyCoordinateData_Common(sexyCoord);
			for (int i = 0; i < 11; i++)
			{
				this.wear.wears[i].id = sexyCoord.clothesId[i];
				if (this.wear.wears[i].color == null)
				{
					this.wear.wears[i].color = new ColorParameter_PBR2();
				}
				this.wear.wears[i].color.FromSexyData(sexyCoord.clothesColor[i], sexyCoord.clothesColor2[i]);
			}
			this.wear.isSwimwear = sexyCoord.swimType;
			this.wear.swimOptTop = !sexyCoord.hideSwimOptTop;
			this.wear.swimOptBtm = !sexyCoord.hideSwimOptBot;
		}

		// Token: 0x06000B2C RID: 2860 RVA: 0x00041800 File Offset: 0x0003FA00
		public void FromSexyCoordinateData(CharFileInfoClothesMale sexyCoord)
		{
			this.InitCoordinate();
			this.FromSexyCoordinateData_Common(sexyCoord);
			int num = 0;
			int num2 = 1;
			if (this.wear.wears[0].color == null)
			{
				this.wear.wears[0].color = new ColorParameter_PBR2();
			}
			if (this.wear.wears[10].color == null)
			{
				this.wear.wears[10].color = new ColorParameter_PBR2();
			}
			this.wear.wears[0].id = sexyCoord.clothesId[num];
			this.wear.wears[0].color.FromSexyData(sexyCoord.clothesColor[num], sexyCoord.clothesColor2[num]);
			this.wear.wears[10].id = sexyCoord.clothesId[num2];
			this.wear.wears[10].color.FromSexyData(sexyCoord.clothesColor[num2], sexyCoord.clothesColor2[num2]);
		}

		// Token: 0x06000B2D RID: 2861 RVA: 0x00041900 File Offset: 0x0003FB00
		private void FromSexyCoordinateData_Common(CharFileInfoClothes sexyCoord)
		{
			for (int i = 0; i < 10; i++)
			{
				CharFileInfoClothes.Accessory accessory = sexyCoord.accessory[i];
				this.acce.slot[i].Set((ACCESSORY_TYPE)accessory.type, accessory.id, accessory.parentKey);
				this.acce.slot[i].addPos = accessory.addPos;
				this.acce.slot[i].addRot = accessory.addRot;
				this.acce.slot[i].addScl = accessory.addScl;
				if (this.acce.slot[i].color == null)
				{
					this.acce.slot[i].color = new ColorParameter_PBR2();
				}
				this.acce.slot[i].color.FromSexyData(accessory.color, accessory.color2);
			}
		}

		// Token: 0x06000B2E RID: 2862 RVA: 0x000419E8 File Offset: 0x0003FBE8
		public void Save(BinaryWriter writer)
		{
			this.Write(writer, CUSTOM_DATA_VERSION.DEBUG_10);
			this.Write(writer, this.sex);
			this.hair.Save(writer, this.sex);
			this.head.Save(writer, this.sex);
			this.body.Save(writer, this.sex);
			this.wear.Save(writer, this.sex);
			this.acce.Save(writer, this.sex);
		}

		// Token: 0x06000B2F RID: 2863 RVA: 0x00041A68 File Offset: 0x0003FC68
		public void Load(TextAsset text, bool female, bool male)
		{
			if (text == null)
			{
				GlobalData.Debug_LogError("不明的二进制卡");
				return;
			}
			using (MemoryStream memoryStream = new MemoryStream(text.bytes))
			{
				using (BinaryReader binaryReader = new BinaryReader(memoryStream))
				{
					if (!this.Load(binaryReader, female, male))
					{
						GlobalData.Debug_LogError("读取失败了");
					}
				}
			}
		}

		// Token: 0x06000B30 RID: 2864 RVA: 0x00041AFC File Offset: 0x0003FCFC
		public void Load(string file, bool female, bool male)
		{
			if (!File.Exists(file))
			{
				return;
			}
			using (FileStream fileStream = new FileStream(file, FileMode.Open, FileAccess.Read))
			{
				using (BinaryReader binaryReader = new BinaryReader(fileStream))
				{
					if (!this.Load(binaryReader, female, male))
					{
						GlobalData.Debug_LogError("读取失败了");
					}
				}
			}
		}

		// Token: 0x06000B31 RID: 2865 RVA: 0x00041B80 File Offset: 0x0003FD80
		protected bool Load(BinaryReader reader, bool female, bool male)
		{
			bool result = true;
			try
			{
				long offset = PNG_Loader.CheckSize(reader);
				reader.BaseStream.Seek(offset, SeekOrigin.Begin);
				string text = reader.ReadString();
				if (text == "【HoneySelectCharaFemale】")
				{
					GlobalData.Debug_Log("蜂蜜精选：女");
					if (female)
					{
						reader.BaseStream.Seek(offset, SeekOrigin.Begin);
						CharFemaleFile charFemaleFile = new CharFemaleFile();
						result = charFemaleFile.Load(reader, true, true);
						this.FromSexyData(charFemaleFile);
					}
					else
					{
						GlobalData.Debug_LogWarning("异性数据");
					}
				}
				else if (text == "【PremiumResortCharaFemale】")
				{
					GlobalData.Debug_Log("性感海滩高级度假村：女");
					if (female)
					{
						reader.BaseStream.Seek(0L, SeekOrigin.Begin);
						CharFemaleFile charFemaleFile2 = new CharFemaleFile();
						result = charFemaleFile2.LoadFromSBPR(reader);
						this.FromSexyData(charFemaleFile2);
					}
					else
					{
						GlobalData.Debug_LogWarning("异性数据");
					}
				}
				else if (text == "【PlayHome_Female】")
				{
					if (female)
					{
						this.Load(reader);
					}
					else
					{
						GlobalData.Debug_LogWarning("异性数据");
					}
				}
				else if (text == "【HoneySelectCharaMale】")
				{
					GlobalData.Debug_Log("蜂蜜精选：男");
					if (male)
					{
						reader.BaseStream.Seek(offset, SeekOrigin.Begin);
						CharMaleFile charMaleFile = new CharMaleFile();
						result = charMaleFile.Load(reader, true, true);
						this.FromSexyData(charMaleFile);
					}
					else
					{
						GlobalData.Debug_LogWarning("异性数据");
					}
				}
				else if (text == "【PremiumResortCharaMale】")
				{
					GlobalData.Debug_Log("性感海滩高级度假村：男");
					if (male)
					{
						reader.BaseStream.Seek(0L, SeekOrigin.Begin);
						CharMaleFile charMaleFile2 = new CharMaleFile();
						result = charMaleFile2.LoadFromSBPR(reader);
						this.FromSexyData(charMaleFile2);
					}
					else
					{
						GlobalData.Debug_LogWarning("异性数据");
					}
				}
				else if (text == "【PlayHome_Male】")
				{
					if (male)
					{
						this.Load(reader);
					}
					else
					{
						GlobalData.Debug_LogWarning("异性数据");
					}
				}
				else
				{
					GlobalData.Debug_LogWarning("无法读取的保存数据:" + text);
				}
			}
			catch (Exception message)
			{
				GlobalData.Debug_LogError(message);
				result = false;
			}
			return result;
		}

		// Token: 0x06000B32 RID: 2866 RVA: 0x00041DBC File Offset: 0x0003FFBC
		public void Load(BinaryReader reader)
		{
			this.Init();
			CUSTOM_DATA_VERSION version = CUSTOM_DATA_VERSION.UNKNOWN;
			this.Read(reader, ref version);
			this.Read(reader, ref this.sex);
			this.hair.Load(reader, this.sex, version);
			this.head.Load(reader, this.sex, version);
			this.body.Load(reader, this.sex, version);
			this.wear.Load(reader, this.sex, version);
			this.acce.Load(reader, this.sex, version);
		}

		// Token: 0x06000B33 RID: 2867 RVA: 0x00041E48 File Offset: 0x00040048
		public void SaveCoordinate(BinaryWriter writer)
		{
			this.Write(writer, CUSTOM_DATA_VERSION.DEBUG_10);
			this.Write(writer, this.sex);
			this.wear.Save(writer, this.sex);
			this.acce.Save(writer, this.sex);
		}

		// Token: 0x06000B34 RID: 2868 RVA: 0x00041E84 File Offset: 0x00040084
		public void LoadCoordinate(BinaryReader reader)
		{
			this.Init();
			CUSTOM_DATA_VERSION version = CUSTOM_DATA_VERSION.UNKNOWN;
			this.Read(reader, ref version);
			this.Read(reader, ref this.sex);
			this.wear.Load(reader, this.sex, version);
			this.acce.Load(reader, this.sex, version);
		}

		// Token: 0x06000B35 RID: 2869 RVA: 0x00041ED8 File Offset: 0x000400D8
		protected void Write(BinaryWriter writer, CUSTOM_DATA_VERSION version)
		{
			writer.Write((int)version);
		}

		// Token: 0x06000B36 RID: 2870 RVA: 0x00041EE4 File Offset: 0x000400E4
		protected void Read(BinaryReader reader, ref CUSTOM_DATA_VERSION version)
		{
			int num = reader.ReadInt32();
			if (num > 10)
			{
				version = CUSTOM_DATA_VERSION.UNKNOWN;
				return;
			}
			version = (CUSTOM_DATA_VERSION)num;
		}

		// Token: 0x06000B37 RID: 2871 RVA: 0x00041F08 File Offset: 0x00040108
		protected void Write(BinaryWriter writer, SEX sex)
		{
			writer.Write((int)sex);
		}

		// Token: 0x06000B38 RID: 2872 RVA: 0x00041F14 File Offset: 0x00040114
		protected void Read(BinaryReader reader, ref SEX sex)
		{
			sex = (SEX)reader.ReadInt32();
		}

		// Token: 0x06000B39 RID: 2873 RVA: 0x00041F20 File Offset: 0x00040120
		public bool CheckWrongParam()
		{
			if (this.sex != SEX.FEMALE && this.sex != SEX.MALE)
			{
				return true;
			}
			if (this.acce.slot.Length != 10)
			{
				return true;
			}
			for (int i = 0; i < this.head.shapeVals.Length; i++)
			{
				if (this.head.shapeVals[i] < 0f || this.head.shapeVals[i] > 1f)
				{
					return true;
				}
			}
			for (int j = 0; j < this.body.shapeVals.Length; j++)
			{
				if (this.body.shapeVals[j] < 0f || this.body.shapeVals[j] > 1f)
				{
					return true;
				}
			}
			return false;
		}

		// Token: 0x04000B8D RID: 2957
		public HairParameter hair;

		// Token: 0x04000B8E RID: 2958
		public HeadParameter head;

		// Token: 0x04000B8F RID: 2959
		public BodyParameter body;

		// Token: 0x04000B90 RID: 2960
		public WearParameter wear;

		// Token: 0x04000B91 RID: 2961
		public AccessoryParameter acce;
	}
}
